<template>
  <div class="subject">
    <div v-if="isShow == false">
      <div class="layout">
        <div class="page-title">
          <span>受试者招募：</span>
        </div>
      </div>
      <div class="sub-list">
        <div
          v-for="item in subjectList"
          :key="item.id"
          class="listitem"
        >
          <div class="list-item">
            <span class="listhover">{{ item.BT }}</span>
            <span>{{ item.CREATEDATE }}</span>
          </div>
          <div>{{ item.XMMS }}</div>
          <div class="list-item">
            <span>阅读次数：{{ item.FWL }}</span>
            <el-button @click="goSubDetail(item.ID)">查看详细</el-button>
          </div>
        </div>
      </div>
    </div>
    <SubDetails
      :id="id"
      @goBack="goBack"
      v-else
    />
  </div>
</template>
<script>
import SubDetails from './detail.vue';
import { getSubjectAPI } from '@/api/index.js';
export default {
    components: { SubDetails },
    data() {
        return {
            topShow: false, //记录当前返回顶部标志的可视状态
            scrollTop: 0, //当前滚动位置
            isShow: false,
            subjectList: [],
            id: null
        };
    },
    mounted() {
        this.subjectData();
    },
    methods: {
        // 获取受试者招募信息接口
        async subjectData() {
            const res = await getSubjectAPI({
                BT: 'null'
            });
            if (res.code == 'succ') {
                this.subjectList = res.result;
            }
        },
        // 跳转详情
        goSubDetail(id) {
            this.id = id;
            this.isShow = true;
            let timer = setInterval(() => {
                let ispeed = Math.floor(-this.scrollTop / 5);
                document.documentElement.scrollTop = document.body.scrollTop = this.scrollTop + ispeed;
                if (this.scrollTop === 0) {
                    clearInterval(timer);
                }
            }, 16);
        },
        goBack() {
            this.isShow = false;
            this.subjectData();
        }
    }
};
</script>
<style scoped>
.subject {
    width: 100%;
    min-height: 100vh;
    font-size: 1.3rem;
}
.sub-list {
    width: 90%;
    margin: 0px auto;
    line-height: 40px;
    padding: 15px;
}
.listitem {
    padding: 20px;
    margin: 10px 0px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    cursor: pointer;
}
.list-item {
    width: 100%;
    display: flex;
    justify-content: space-between;
}
.listhover:hover {
    color: #409eff;
}
::v-deep .el-form-item--small.el-form-item {
    /* margin-bottom: 5px; */
}
</style>
